package top.hkyzf.study.leetcode.string;

import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

/**
 * description:
 *
 * @author zhufeng
 * @version 1.0
 * @date 2024-3-17 10:42
 */
public class 字符串及其反转中是否存在同一子字符串_100248 {
    public boolean isSubstringPresent(String s) {
        Set<String> subSet = new HashSet<>();
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i-1) == s.charAt(i)) {
                return true;
            }
            subSet.add(s.substring(i-1, i+1));
        }
        for (int i = s.length()-2; i >= 0; i--) {
            if (subSet.contains(String.valueOf(s.charAt(i + 1)) + s.charAt(i))) {
                return true;
            }
        }
        return false;
    }

    @Test
    public void testIsSub () {
        String s = "abcba";
        System.out.println(isSubstringPresent(s));
    }
}
